<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    /*var arr = [1,2,3,4,5,6];
    var sum = 0;
    for( var i = 0, leg =arr.length; i < leg; i++){
        sum = sum +arr[i];
    }
    console.log(sum/arr.length)*/
    var arr = [10,20,30,34,67];
    function avg(array){  // 封装求平均值函数
        var len = array.length;  // 数组的长度
        var sum = 0;
        for(var i=0; i<len; i++)
        {
            sum += array[i];   //     sum = sum +array[i];
        }
        return sum / len;
    }
    //a*=3   a= a*3
    console.log(avg(arr));
</script>
</body>
</html>